Skip to content

[RAA-8779]-[TH]-[Added in script to resolve all reference after Redoc…#2826

Merged
georgeCraftReferrals merged 2 commits into
developfrom
feature/RAA-8779
Jun 25, 2026
Merged

[RAA-8779]-[TH]-[Added in script to resolve all reference after Redoc…#2826
georgeCraftReferrals merged 2 commits into
developfrom
feature/RAA-8779

Conversation

@georgeCraftReferrals

Copy link
Copy Markdown
Contributor

…ly update]-[GC]

Summary

  • Routine Change
  • ❗ Breaking Change
  • 🤖 Operational or Infrastructure Change
  • ✨ New Feature
  • ⚠️ Potential issues that might be caused by this change

Add any other relevant notes or explanations here. Remove this line if you have nothing to add.

Reviews Required

  • Dev
  • Test
  • Tech Author
  • Product Owner

Review Checklist

ℹ️ This section is to be filled in by the reviewer.

  • I have reviewed the changes in this PR and they fill all or part of the acceptance criteria of the ticket, and the code is in a mergeable state.
  • If there were infrastructure, operational, or build changes, I have made sure there is sufficient evidence that the changes will work.
  • I have ensured the changelog has been updated by the submitter, if necessary.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a build-time Python script to post-process the bundled OpenAPI JSON, resolving any remaining {"$ref": ".../*.json"} objects that Redocly v2 leaves inside example payloads, and wires it into the npm run publish pipeline so the generated build/e-referrals-service-api.json contains fully inlined examples.

Changes:

  • Added scripts/resolve_example_refs.py to replace remaining JSON-file $ref objects (primarily under components/{stu3,r4}/examples) with file contents during publishing.
  • Updated package.json publish script to run the new resolver between redocly bundle and existing set_version.py / populate_placeholders.py.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
scripts/resolve_example_refs.py New stdin→stdout transformer to inline example JSON $refs after bundling.
package.json Inserts the resolver into the publish pipeline.

Comment on lines +5 to +16
Reads a bundled OpenAPI spec on stdin and resolves any remaining $ref
objects found inside example 'value' fields. This is needed because
Redocly CLI v2 no longer dereferences $ref inside example values
during bundling.

The script walks the entire spec looking for objects of the form:
{"$ref": "some/path/to/file.json"}

that appear inside example value contexts, loads the referenced JSON
file from disk relative to the specification directory, and replaces
the $ref object with the actual file content.

Comment on lines +50 to +54
# Try both stu3 and r4 directories
for subdir in ["stu3", "r4"]:
candidate = os.path.join(SPEC_COMPONENTS_DIR, subdir, relative_from_examples)
if os.path.isfile(candidate):
return candidate
Comment on lines +59 to +83
def resolve_refs(obj):
"""
Recursively walk the parsed JSON object. When we find a dict that
is exactly {"$ref": "<path>"} where the path points to a .json
file, load that file and return its content instead.
"""
if isinstance(obj, dict):
if list(obj.keys()) == ["$ref"] and obj["$ref"].endswith(".json"):
ref_path = obj["$ref"]
abs_path = resolve_ref_path(ref_path)
if abs_path:
with open(abs_path, "r") as f:
return json.load(f)
else:
print(
f"Warning: Could not resolve $ref: {ref_path}",
file=sys.stderr,
)
return obj
else:
return {k: resolve_refs(v) for k, v in obj.items()}
elif isinstance(obj, list):
return [resolve_refs(item) for item in obj]
else:
return obj

@tomhague11 tomhague11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tomhague11 tomhague11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@georgeCraftReferrals georgeCraftReferrals merged commit 02ef632 into develop Jun 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants